[XENBUS] Improve the code for waiting for devices to connect. Provide
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 30 Jun 2006 16:02:22 +0000 (17:02 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 30 Jun 2006 16:02:22 +0000 (17:02 +0100)
a more useful error when devices fail to connect.
From: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c

index 454f1a1eee29ffad61c43576a360d76728fdfec6..982b4455a4869c1a2018ba52743a281cea5e2297 100644 (file)
@@ -886,29 +886,19 @@ void unregister_xenstore_notifier(struct notifier_block *nb)
 EXPORT_SYMBOL_GPL(unregister_xenstore_notifier);
 
 
-static int all_devices_ready_(struct device *dev, void *data)
+static int find_disconnected_device_(struct device *dev, void *data)
 {
        struct xenbus_device *xendev = to_xenbus_device(dev);
-       int *result = data;
 
-       if (xendev->state != XenbusStateConnected) {
-               *result = 0;
-               return 1;
-       }
-
-       return 0;
+       return (xendev->state == XenbusStateConnected) ? 0 : 1;
 }
 
-
-static int all_devices_ready(void)
+static struct device *find_disconnected_device(struct device *start)
 {
-       int ready = 1;
-       bus_for_each_dev(&xenbus_frontend.bus, NULL, &ready,
-                        all_devices_ready_);
-       return ready;
+       return bus_find_device(&xenbus_frontend.bus, start, NULL,
+                              find_disconnected_device_);
 }
 
-
 void xenbus_probe(void *unused)
 {
        BUG_ON((xenstored_ready <= 0));
@@ -1077,17 +1067,28 @@ postcore_initcall(xenbus_probe_init);
 static int __init wait_for_devices(void)
 {
        unsigned long timeout = jiffies + 10*HZ;
+       struct device *dev = NULL;
+       struct xenbus_device *xendev;
 
        if (!is_running_on_xen())
                return -ENODEV;
 
        while (time_before(jiffies, timeout)) {
-               if (all_devices_ready())
+               if ((dev = find_disconnected_device(NULL)) == NULL)
                        return 0;
+               put_device(dev);
                schedule_timeout_interruptible(HZ/10);
        }
 
-       printk(KERN_WARNING "XENBUS: Timeout connecting to devices!\n");
+       while (dev != NULL) {
+               xendev = to_xenbus_device(dev);
+
+               printk(KERN_WARNING "XENBUS: Timeout connecting to device: %s\n",
+                      xendev->nodename);
+
+               dev = find_disconnected_device(dev);
+       }
+
        return 0;
 }